所有参考资料贴在最后。

1. 介绍

在线试验场
Composer Playground

文档

2. 创建新business network

Deploy a new business network1

Deploy a new business network2

3. 链接business network

connect

ALC FILE

  • About文件 – Markdown格式的说明文件,试验场默认将显示该文件的内容。
  • Access Control List – 决定了哪些参与者可以看到哪些资产。
  • Add按钮 – 必要时可向项目中添加额外的文件。
  • Deploy按钮 – 可将对项目文件的改动应用给当前已连接的区块链实例或模拟器。
  • Import功能可将试验场的内容替换为指定的其他内容。
  • Export功能可将整个解决方案打包为一个文件,并转移到其他环境中使用。

界面右侧的主区域显示了所选文件的编辑器或查看器。此外页面顶部的Define/Test选项卡可供我们在开发或测试模式之间切换。最后,页面右上角可供我们(在本地版本中)模拟另一个区块链用户的身份,连接至自己的线上区块链实例,或开始在Web浏览器中模拟。在线版试验场目前仅支持模拟器模式。^foot1

4. 添加一个model file

Model files define the assets, participants, transactions, and events in our business network.

  • Model文件 – 定义了项目中涉及的资产、参与者,以及事务。

Add a file

code in the model file 1

code in the model file 2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*This domain model defines a single asset type Commodity and single participant type Trader and a single transaction type Trade that is used to modify the owner of a commodity.*/
namespace org.acme.mynetwork
asset Commodity identified by tradingSymbol {
o String tradingSymbol
o String description
o String mainExchange
o Double quantity
--> Trader owner
}
participant Trader identified by tradeId {
o String tradeId
o String firstName
o String lastName
}
transaction Trade {
--> Commodity commodity
--> Trader newOwner
}

5. 添加transaction processor script file

define the transaction logic for the business network.

  • Script文件 – 以JavaScript实现的事务逻辑。

add script file

1
2
3
4
5
6
7
8
9
10
11
12
/**
* Track the trade of a commodity from one trader to another
* @param {org.acme.mynetwork.Trade} trade - the trade to be processed
* @transaction
*/
function tradeCommodity(trade) {
trade.commodity.owner = trade.newOwner;
return getAssetRegistry('org.acme.mynetwork.Commodity')
.then(function (assetRegistry) {
return assetRegistry.update(trade.commodity);
});
}

This function simply changes the owner property on a commodity based on the newOwner property on an incoming Trade transaction. It then persists the modified Commodity back into the asset registry, used to store Commodity instances.

6. Access control

define the access control rules for business networks.

7. 发布已更新的business network

update1

update2

8. 测试business network定义

test

9. 创建participants

a Trader participant1

a Trader participant2

a Trader participant3

Trader view

10. 创建asset

Create New Asset

asset code1

asset code2

Commodity tab

11. 在participants间交易commodity

trade1

trade2

1
2
3
4
5
{
"$class": "org.acme.mynetwork.Trade",
"commodity": "resource:org.acme.mynetwork.Commodity#ABC",
"newOwner": "resource:org.acme.mynetwork.Trader#TRADER2"
}

submit

result

history record